#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
//http://oj33.cn/contest.php?cid=1075
//https://blog.csdn.net/qq_37482202/article/details/89513877
int n, m;
int Uni[30001];
int rank1[30001];
int com[30001];
int find(int x)
{
	if (x == Uni[x])
	{
		return x;

	}
	else
	{
		Uni[x] = find(Uni[x]);
		return Uni[x];
	}
}
void merge(int a, int b)
{
	int i = find(a);
	int j = find(b);
	/*if(rank1[i]<=rank1[j])
		Uni[find(i)] = j;
	else
		Uni[find(j)] = i;
	if (rank1[i] == rank1[j] && i != j)
	{
		rank1[j]++;
	}*/
	Uni[find(i)] = j;
}
int main()
{
	for (int i = 0; i < 10001; i++)
	{
		Uni[i] = i;
	    rank1[i] = 1;
	}
	char a;
	int b, c;
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		cin >> a >> b >> c;
		if (a == 'F')
		{
			merge(b, c);
		}
		else
		{
			if (com[b] == 0)
			{
				com[b] = find(c);
			}
			else-
			{
				merge(com[b], c)
					;
			}
			if (com[c] == 0)
			{
				com[c] == find(b);
			}
			else
			{
				merge(com[c], b);

			}
		}
	}int ans = 0;
	for (int i = 1; i <= n; i++)
		if (Uni[i] == i)ans++;
	cout << ans<<endl;
	return 0;
}